
import pygame
from commonModule import *


# 我方小飞机
class MyPlane(pygame.sprite.Sprite):
    def __init__(self, bg_size):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load("./images/me1.png").convert_alpha()
        self.image2 = pygame.image.load("./images/me2.png").convert_alpha()
        # 添加被撞毁图片
        self.destore_images = [loadImage("me_destroy_1.png"), loadImage(
            "me_destroy_2.png"), loadImage("me_destroy_3.png"), loadImage("me_destroy_4.png")]
        self.active = True
        self.rect = self.image.get_rect()
        self.width, self.height = bg_size
        self.rect.centerx = self.width/2
        self.rect.bottom = self.height - 60
        self.speed = 10
        self.mask = pygame.mask.from_surface(self.image)
        # 复活无敌状态
        self.invincible = False

    # 控制小球移动方法
    def moveUp(self):
        self.rect.top -= self.speed
        if self.rect.top < 0:
            self.rect.top = 0

    def moveDown(self):
        self.rect.bottom += self.speed
        if self.rect.bottom > self.height - 60:
            self.rect.bottom = self.height - 60

    def moveLeft(self):
        self.rect.left -= self.speed
        if self.rect.left < 0:
            self.rect.left = 0

    def moveRight(self):
        self.rect.right += self.speed
        if self.rect.right > self.width:
            self.rect.right = self.width

    # 重载我放飞机
    def reset(self):
        self.active = True
        self.rect.centerx = self.width/2
        self.rect.bottom = self.height - 60
        self.invincible = True
